#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
	int x=0,y=0,z=0,a=0,b=0,c=0,flag=0,Flag=0;
	char ch,name[30],ty[2];
	printf("命令模式为wc.exe [参数] [文件名]:\n");
	printf("请输入要输出的类型参数（-c为字符数，-w为单词数，-s为句子数,-k为空行数，-t为换行数，-z为注释数）:\n");
	printf("注释以//为区分\n");
	scanf("%s",ty);
	printf("请输入文件名：\n");
    scanf("%s",name);
	FILE*fp=fopen(name,"r");
    if(fp==NULL){
        printf("打开文件失败\n");
    }
	while((ch=getc(fp))!=EOF){
		if(ch==' '){
				y++;
				x=x-1;
				flag=0;
		}
		else if((ch=='.')||(ch=='!')||(ch=='?')){
				z++;
				y++;
					flag=0;
		}
        else if((ch==',')||(ch==':')||(ch==';')){
				y++;
					flag=0;
		}
		 else if((ch=='\n')&&(flag==0)){
				a++;
				flag=1;
		}
		  else if((ch=='\n')&&(flag==1)){
				a++;
				b++;
		}
		  else if((ch=='/')&&(Flag==0)){
			Flag=1;
				flag=0;
		}
		    else if((ch=='/')&&(Flag==1)){
			Flag=0;
				flag=0;
			c++;
		}
		x++;
	}
	if(ty[1]=='c'){
		printf("字符=%d\n",x);
	}
	if(ty[1]=='w'){
		printf("单词=%d\n",y);
	}
	if(ty[1]=='s'){
		printf("句子=%d\n",z);
	}
	if(ty[1]=='t'){
		printf("换行=%d\n",a);
	}
	if(ty[1]=='k'){
		printf("空行=%d\n",b);
	}
	if(ty[1]=='z'){
		printf("注释=%d\n",c);
	}
	fclose(fp);
    system("pause");
    return 0;
}